﻿var newWindowManager = new DialogManager();

// 组名右键菜单
var groupmenu = new contextMenu(
                        {
                            menuID: "GroupMenu",
                            targetEle: "title02" //
                        },
                        {
                            bindings: {
                                'addGroup': function(o) {
                                    addGroupOperate();
                                },
                                'addUser': function(o) {
                                    maskBody(50, "maskDiv");
                                    newWindowManager.Open("dialog/adduserfriend.aspx?Groupid=" + o.id, "addUser", "height=300px, width=400px, top=200, left=800, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no", false,"");
                                },
                                'deleteGroup': function(o) {
                                    var groupUserCount = chatblog.usercate.chRoom.GetGroupUserList(o.id).value;
                                    if (groupUserCount > 0) {
                                        alert("对不起，好友组：" + o.childNodes[0].nodeValue + " 中有好友，请在清空该组中的好友之后再删除该组！");
                                        return;
                                    }
                                    if (confirm("删除组：" + o.childNodes[0].nodeValue + " ?") == true) {
                                        var result = chatblog.usercate.chRoom.DeleteGroup(o.id, o.childNodes[0].nodeValue);
                                        var doorPDiv = document.getElementById(doorPId);
                                        doorPDiv.innerHTML = chatblog.usercate.chRoom.GetDoorPInnerHtml().value;
                                        InitAgain();
                                        alert("已删除");
                                    }
                                },
                                'renameGroup': function(o) {
                                    renameGroupOperate(o);
                                }
                            }
                        }
                    );

groupmenu.buildContextMenu();

// 组内用户右键菜单
var cmenu = new contextMenu(
                    {
                        menuID: "bmenu",
                        targetEle: "contextMenu0"
                    },
	 	                {
	 	                    bindings: {
	 	                        'rename': function(o) {
	 	                            newWindowManager.Open("dialog/ChangeUserName.aspx?userid=" + o.getElementsByTagName('input')[0].value + "&username=" + o.innerText + "&groupid=" + o.id, "rename",
	 	                             "height=300px, width=400px, top=200, left=800, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no", false,"");
	 	                        },
	 	                        'edit': function(o) {
	 	                            newWindowManager.Open("dialog/ChangeUserGroup.aspx?userid=" + o.getElementsByTagName('input')[0].value + "&groupid=" + o.id, "rename",
	 	                             "height=300px, width=400px, top=200, left=800, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no", false,"");
	 	                        },
	 	                        'del': function(o) {
	 	                            if (confirm("删除 " + o.innerText + " ?") == true) {
	 	                                var uid = o.getElementsByTagName('input')[0].value;
	 	                                var result = chatblog.usercate.chRoom.DeleteUser(uid, o.id);
	 	                                var doorPDiv = document.getElementById(doorPId);
	 	                                doorPDiv.innerHTML = chatblog.usercate.chRoom.GetDoorPInnerHtml().value;
	 	                                InitAgain();
	 	                                alert("已删除");
	 	                            }
	 	                        },
	 	                        'prop': function(o) { alert("查看详细 组ID：" + o.id + "；用户ID：" + o.getElementsByTagName('input')[0].value); },
	 	                        'add': function(o) {
	 	                            //maskBody(50, "maskDiv");
	 	                            newWindowManager.Open("dialog/adduserfriend.aspx?Groupid=" + o.id, "addUser", "height=300px, width=400px, top=200, left=800, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no", false,"");
	 	                        }
	 	                    }
	 	                }
 	                );

cmenu.buildContextMenu();


window.onbeforeunload = function(evt) {
    evt = evt || window.event;
    var event = evt;
    newWindowManager.Clear(true);
    var result = chatblog.usercate.chRoom.LoginOut().value;
    if(Statustimeid!=null)
        clearInterval(Statustimeid);
}

//window.open(window.location.href, "_self", "height=500px, width=250px, top=0, left=800, toolbar=no, menubar=no, scrollbars=no, resizable=yes,location=no, status=no", true);
//if(document.clientHeight!=

//var needDoMove = false;
//var needDoResize = false; 
//needDoResize = (document.documentElement.offsetWidth != 250 || document.documentElement.offsetHeight != 500);
//if (Sys.firefox) {
//    needDoMove = (window.screenX != 800 || window.screenY != 0);
//}
//else {
//    needDoMove = (window.screenLeft != 800 || window.screenTop != 0);
//}
//if (needDoResize == true) {
//    window.resizeTo(250, 500);
//}
//if (needDoMove == true) {
//    window.moveTo(800, 0);
//}

//设置定时器
var Statustimeid = setInterval(timeInit, 1000);
var _currentUserid = chatblog.usercate.chRoom.GetCurrentUserID().value
//定时器方法
function timeInit() {
    var result = chatblog.usercate.chRoom.GetCurrentChatStatus();
    if (result.value != null && result.value == "") {
        var dynResult = chatblog.usercate.chRoom.getDynamicChatRoomUserTos();
        if (dynResult.value != null && dynResult.value != "") {
            var dynamicUsers = eval(dynResult.value);
            for (var i = 0; i < dynamicUsers.length; i++) {
                if (_currentUserid != dynamicUsers[i].userid) {
                    addChatRoom("", dynamicUsers[i].recid, dynamicUsers[i].userid);
                }
                else {
                    alert("不能和自己聊天");
                }
                chatblog.usercate.chRoom.removeDynamicChatRoomUserTos();
            }
        }
        changeUserStatus();
        refreshFriendStatus();
    }
    else {
        alert(result.value);
        window.location.href = "ChatSetup.aspx?redirect=1";
    } 
}



//刷新好友的头像闪动
function refreshFriendStatus() {
    var newMsgInfoArray = new Array();
    var newMsgUsers = chatblog.usercate.chRoom.getNewMsgUsers().value;  //获取最新信息用户列表，用来记录用户头像闪动
    if (newMsgUsers != null && newMsgUsers.length != null && newMsgUsers.length > 0) {
        var hasflicker = false;
        for (var i = 0; i < newMsgUsers.length; i++) {
            if ((newWindowManager.ExistDialogByUserID(newMsgUsers[i]) == null) && (!exsitUserFlicker(newMsgUsers[i]))) {
                flickerUserId(newMsgUsers[i]);  //好友闪动的时候闪动好友分组
                hasflicker = true;

                newMsgInfoArray.push([newMsgUsers[i], -1]); 
            }
        }
        if (hasflicker == true) {
            //window.focus();
            window.blur();
            if (newMsgInfoArray.length > 0) {
                var left = screen.width;
                var top = screen.height;
                var infoWin = window.open("dialog/SysInfo.htm?info=" + newMsgInfoArray.toString(), "sysInfo", "height=" + 200 + "px, width=" + 250 + "px, top=" + top + "px,left=" + left + "px, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no");
                var timeoutid = setTimeout(function() {
                    infoWin.opener = null;
                    infoWin.open("", "_self");
                    infoWin.close();
                    clearTimeout(timeoutid);
                }, 2000);
            }
        } 
    }
}

//好友头像闪动
function flickerUserId(userid) {
    var Ds = $("#" + doorPId)[0].getElementsByTagName("div");
    for (var i = 0; i < Ds.length; i++) {
        var hidenInputList = Ds[i].getElementsByTagName("input");
        for (var j = 0; j < hidenInputList.length; j++) {
            var hideInput = hidenInputList[j];
            if ((hideInput != null) && (hideInput.value == userid)) {
                var spanObj = Ds[i].getElementsByTagName("span")[j];
                var imgObj = Ds[i].getElementsByTagName("img")[j];
                var imgtimeid = setInterval(function() { imgObj.style.visibility = (imgObj.style.visibility == "visible" || imgObj.style.visibility == "") ? "hidden" : "visible"; }, 500);
                userIdTimeListManage.push([userid, imgtimeid]);
                flickerGroupId(spanObj.id);                           
                break;
            }
        }
    }         
}
//移除好友头像闪动
function removeImgTimeIdByUserId(userid) {
    for (var i = 0; i < userIdTimeListManage.length; i++) {
        if (userIdTimeListManage[i][0] == userid) {
            clearInterval(userIdTimeListManage[i][1]);
            userIdTimeListManage.splice(i, 1);
            break;
        }
    }

    var Ds = $("#" + doorPId + " > div");
    for (var i = 0; i < Ds.length; i++) {
        var foundUserId = false;
        var hidenInputList = Ds[i].getElementsByTagName("input");
        for (var j = 0; j < hidenInputList.length; j++) {
            var hideInput = hidenInputList[j];
            if ((hideInput != null) && (hideInput.value == userid)) {
                var spanObj = Ds[i].getElementsByTagName("span")[j];
                var imgObj = Ds[i].getElementsByTagName("img")[j];
                imgObj.style.visibility = "visible";
                foundUserId = true;
                break;
            }
        }
        
        if (foundUserId) {
            var canRemoveGroupFlicker = true ;
            for (var j = 0; j < hidenInputList.length; j++) {
                var hideInput = hidenInputList[j];
                if (exsitUserFlicker(hideInput.value) && hideInput.value != userid) {
                    canRemoveGroupFlicker = false;
                    break;
                }
            }  
            if(canRemoveGroupFlicker) 
                removeGroupTimeIdByGroupId(spanObj.id);
        } 
    }
}

//好友分组头像闪动
function flickerGroupId(groupId) {
    var existFilker = false;
    for (var j = 0; j < groupIdTimeListManage.length; j++) {
        if (groupIdTimeListManage[j][0] == groupId) {
            existFilker = true;
            return;
        }
    }

    Ts = $("#" + doorPId + " > h2");
    var beingToFlikerIndex = -1;
    for (var i = 0; i < Ts.length; i++) {
        if (Ts[i].id == groupId) {
            beingToFlikerIndex = i;
            break;
        }
    }

    if (beingToFlikerIndex >= 0) {
        var newImg = document.createElement("img");
        newImg.id = GetGuid();
        newImg.src = "img/regular_smile.gif";
        newImg.title = "您有新的消息";
        //DoorP .childNodes
        Ts[beingToFlikerIndex].insertBefore(newImg, Ts[beingToFlikerIndex].childNodes[0]);
        var newImgTimeId = setInterval(function() { newImg.style.visibility = (newImg.style.visibility == "visible" || newImg.style.visibility == "") ? "hidden" : "visible"; }, 500);
        groupIdTimeListManage.push([groupId, newImgTimeId]);
    }
}

//移除好友分组头像闪动
function removeGroupTimeIdByGroupId(groupId) {
    for (var i = 0; i < groupIdTimeListManage.length; i++) {
        if (groupIdTimeListManage[i][0] == groupId) {
            clearInterval(groupIdTimeListManage[i][1]);
            groupIdTimeListManage.splice(i, 1);
            break;
        }
    }
    Ts = $("#" + doorPId + " > h2");
    var beingToRemoveFlikerIndex = -1;
    for (var i = 0; i < Ts.length; i++) {
        if (Ts[i].id == groupId) {
            beingToRemoveFlikerIndex = i;
            break;
        }
    }
    if (beingToRemoveFlikerIndex >= 0) {
        var imgObjs = Ts[beingToRemoveFlikerIndex].getElementsByTagName("img");
        if (imgObjs != null && imgObjs.length > 0) {
            Ts[beingToRemoveFlikerIndex].removeChild(imgObjs[0]);
        }
    }
}


function exsitUserFlicker(userid) {
    for (var i = 0; i < userIdTimeListManage.length; i++) {
        if (userIdTimeListManage[i][0] == userid) {
            return true;
        }
    }
    return false;
}

var onlineUsers;
//改变好友状态
function changeUserStatus() {
    //return;
    var changeAllStatus = false;
    var allUsers = getAllUsers();
    //var oldOnlineUsers = onlineUsers;
    var imgObj;
    var systemInfoString = "";
    var sysInfoArray = new Array();
    var newAllUsers = chatblog.usercate.chRoom.getAllUserStatus().value;
    if (newAllUsers != null && newAllUsers != "") {
        var allUserStatusArray = resolveAllUserStatus(newAllUsers); //alert(allUserStatusArray[0].isOnline);

        var hasNoNewUserTo = true;
        if (allUserStatusArray.length != null && allUserStatusArray.length > 0) {
            for (var i = 0; i < allUserStatusArray.length; i++) {
                var found = false;
                for (var j = 0; j < allUsers.length; j++) {
                    if (allUsers[j][0] == allUserStatusArray[i].user_to) {
                        found = true;
                        break;
                    }
                }
                if (found == false) {
                    hasNoNewUserTo = false;
                    break;
                }
            }
            if (hasNoNewUserTo == false) {
                var htmlResult = chatblog.usercate.chRoom.GetDoorPInnerHtml().value;
                if (htmlResult != null && htmlResult != "") {
                    RefreshGroupDiv();
                }
            }
            else {
                for (var i = 0; i < allUserStatusArray.length; i++) {
                    var found = false;
                    for (var j = 0; j < allUsers.length; j++) {
                        if (allUsers[j][0] == allUserStatusArray[i].user_to) {
                            found = true;
                            break;
                        }
                    }
                    if (found == true) {
                        var imgObj = allUsers[j][2];  //getImgFromUserId(allUserStatusArray[i][0]);
                        //现在不在线
                        if (allUserStatusArray[i].isOnline == 0) {
                            imgObj.alt = "不在线";
                            imgObj.title = "该用户不在线";
                            if (allUsers[j][1] == 0 || allUsers[j][1] == 1) {
                                imgObj.src = getNoColorImg(imgObj.src);            //"img/regular_smile_nocolor.gif";
                                if (allUsers[j][1] == 1) {
                                    systemInfoString += "<span>好友：" + allUsers[j][0] + "下线了！</span><br/>";
                                    removeUserPosition(j, false, allUsers);   //移动好友到下线的位置
                                    sysInfoArray.push([allUsers[j][0],0]);
                                }
                            }
                            else {
                                imgObj.src = "img/regular_smile_nocolor.gif";
                                systemInfoString += "<span>好友：" + allUsers[j][0] + "注册了！</span><br/>";
                                removeUserPosition(j, false, allUsers);  //移动好友到下线的位置
                                sysInfoArray.push([allUsers[j][0],1]);
                            }
                        }
                        //现在在线
                        else if (allUserStatusArray[i].isOnline == 1) {
                            imgObj.alt = "在线";
                            imgObj.title = "该用户在线";
                            if (allUsers[j][1] == 0 || allUsers[j][1] == 1) {
                                imgObj.src = getColorImg(imgObj.src);
                                if (allUsers[j][1] == 0) {
                                    systemInfoString += "<span>好友：" + allUsers[j][0] + "上线了！</span><br/>";
                                    removeUserPosition(j, true, allUsers);    //移动好友到上线的位置
                                    sysInfoArray.push([allUsers[j][0], 2]);
                                }
                            }
                            else {
                                imgObj.src = "img/regular_smile.gif";
                                systemInfoString += "<span>好友：" + allUsers[j][0] + "注册了并在线上！</span><br/>";
                                removeUserPosition(j, true, allUsers);      //移动好友到上线的位置
                                sysInfoArray.push([allUsers[j][0], 3]);
                                
                            }
                        }
                        //现在未注册
                        else {
                            imgObj.alt = "未注册";
                            imgObj.src = "img/notuser.ico";
                            imgObj.title = "暂时还未注册成系统用户";
                        }
                    }
                }                       
            }
        }

    }
    changeAllStatus = (systemInfoString != "");
     if (systemInfoString != "") {//alert(sysInfoArray.toString());    
         var left = screen.width ;
         var top = screen .height  ;   
         var minHeight = 160;
         var maxHeight = 250;  //sysInfoArray.length * 40 + 100;
         var width = 250; //alert(window .document.body.offsetHeight);
         //window.open("dialog/SysInfo.htm");
         var infoWin = window.open("dialog/SysInfo.htm?info=" + sysInfoArray.toString(), "sysInfo", "height=" + minHeight + "px, width=" + width + "px, top=" + top + "px,left=" + left + "px, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no");
         var timeoutid = setTimeout(function() {
             infoWin.opener = null;
             infoWin.open("","_self");
             infoWin.close();
             clearTimeout(timeoutid );
         }, 2000);
//         var resizeHeight = 10;
//         var infoWinTimeId = setInterval(function() {
//             if (infoWin.outerHeight >= minHeight && infoWin.outerHeight < maxHeight && resizeHeight > 0)
//                 resizeHeight = 10; //infoWin.moveBy(-5, 0);
//             else if (infoWin.outerHeight > maxHeight)
//                 resizeHeight = -10;

//             if (infoWin.outerHeight < minHeight) {
//                 clearInterval(infoWinTimeId);
//                 infoWin.opener = null;
//                 infoWin.open("", "_self");
//                 infoWin.close();
//             }
//             infoWin.resizeBy(0, resizeHeight);
//             if (resizeHeight < 0) {
//                 infoWin.moveBy(0, 10);
//             }
//         }, 500);
         //alert(1);
     }
}

//移动好友的位置
//indexfrom 初始位置
//isup 向上移动或者向下移动，如果好友上线 isup =true;如果下线 isup =false
//allusers 所有好友列表 =getAllUsers(); 
function removeUserPosition(indexfrom, isup, allusers) {
    if (indexfrom >= 0 && indexfrom < allusers.length) {
        var imgObj = allusers[indexfrom][2];        //好友的头像
        var spanObj = imgObj.parentNode;  // 好友的 span
        var parentObj = spanObj.parentNode;      //好友分组的组内Div
        var brObj = spanObj.nextSibling;    // 好友的 br
        var cloneSpan = spanObj;
        if (parentObj.getElementsByTagName('span').length > 1) {
            parentObj.removeChild(spanObj);
            parentObj.removeChild(brObj);
            //上线
            if (isup == true) {
                if (parentObj.childNodes[0] != null) {             //插入到所有的好友上面
                    parentObj.insertBefore(brObj, parentObj.childNodes[0]);
                    parentObj.insertBefore(spanObj, parentObj.childNodes[0]);
                }
            }
            //下线
            else {
                var lastUnLineIndex = 0;
                var imgList = parentObj.getElementsByTagName('img');
                var found = false;
                for (var i = 0; i < imgList.length; i++) {
                    if (imgList[i].src.indexOf("img/notuser.ico") > 0) {
                        found = true;
                        break;
                    }
                }
                if (found == true) {                          //此分组有未注册好友，移动到未注册好友的前面
                    parentObj.insertBefore(brObj, parentObj.childNodes[2 * i]);
                    parentObj.insertBefore(spanObj, parentObj.childNodes[2 * i]);
                }
                else {                                        //此分组没有未注册好友，移动到最后
                    parentObj.appendChild(spanObj);
                    parentObj.appendChild(brObj);
                }
            }
        }
    }
}
//获取所有好友列表
function getAllUsers() {
    var allUsers = new Array();
    Ds = $("#"+doorPId+ " > div");
    for (var i = 0; i < Ds.length; i++) {
        var spanList = Ds[i].getElementsByTagName('span');
        var imgList = Ds[i].getElementsByTagName('img');
        if (spanList.length == null || spanList.length == 0)
            continue;
        for (var j = 0; j < spanList.length; j++) {
            var hideInput = spanList[j].getElementsByTagName("input")[0];
            if (hideInput != null && hideInput.value != null && hideInput.value != "") {
                var imgObj = imgList[j]
                var status = 0;
                if (imgObj.alt == "在线")
                    status = 1;  //在线
                else if (imgObj.alt == "不在线")
                    status = 0;  //不在线
                else if (imgObj.alt = "未知")
                    status = 2;  //未知用户
                else
                    status = 3; //未注册
                allUsers.push([hideInput.value, status, imgObj]);
            }
        }
    }
    return allUsers;
}
//分析通过Ajax从数据库中获取的所有好友的状态 （userid =status）
function resolveAllUserStatus(allUserStatusStr) {
    var userStatusArray = eval(allUserStatusStr);         
    return userStatusArray;
}
function getNoColorImg(imgSrc) {
    var newSrc = "";
    var suffixName = ".gif";
    var nocolorSuffix = "_nocolor";
    if (imgSrc.length <= (suffixName.length + nocolorSuffix.length))
        return imgSrc.substr(0, imgSrc.length - suffixName.length) + nocolorSuffix + suffixName;
    else {
        if (imgSrc.substr(imgSrc.length - suffixName.length - nocolorSuffix.length, suffixName.length + nocolorSuffix.length) == (nocolorSuffix + suffixName))
            return imgSrc;
        else
            return imgSrc.substr(0, imgSrc.length - suffixName.length) + nocolorSuffix + suffixName;
    }
}
function getColorImg(imgSrc) {
    var newSrc = "";
    var suffixName = ".gif";
    var nocolorSuffix = "_nocolor";
    if (imgSrc.length <= (suffixName.length + nocolorSuffix.length))
        return imgSrc;
    else {
        if (imgSrc.substr(imgSrc.length - suffixName.length - nocolorSuffix.length, suffixName.length + nocolorSuffix.length) == (nocolorSuffix + suffixName))
            return imgSrc.substr(0, imgSrc.length - suffixName.length - nocolorSuffix.length) + suffixName;
        else
            return imgSrc;
    }
}
function getImgSrc(imgSrc, toNoColor) {
    var newSrc = "";
    var suffixName = ".gif";
    var nocolorSuffix = "_nocolor";
    if (toNoColor) {
        newSrc = imgSrc.substr(0, imgSrc.length - suffixName.length) + nocolorSuffix + suffixName;
    }
    else {
        newSrc = imgSrc.substr(0, imgSrc.length - suffixName.length - nocolorSuffix.length) + suffixName;
    }
    return newSrc;
}

//点击好友进行聊天
function addChatRoom(groupid, recid, useridto) {
    var groupidStr = "";
    if (groupid != "")
        groupidStr = "&groupid=" + groupid;
    newWindowManager.Open("dialog/newRoom.aspx?torecid=" + recid + groupidStr , recid , "height=500px, width=660px, top=200, left=200, toolbar=no, menubar=no, scrollbars=no, resizable=yes,location=no, status=no", true,useridto );
}

//打开窗口 管理器
function DialogManager() {
    this.ChatRoomArray = new Array();
    this.DialogArray = new Array();

    //是否存在非聊天室窗口
    this.ExistNotChatRoom = function() {
        for (var i = 0; i < this.DialogArray.length; i++)
            if (this.DialogArray[i][1] == false)
            return true;
        return false;
    }
    //是否存在名称为name的打开的窗口
    this.ExistDialog = function(name) {
        for (var i = 0; i < this.DialogArray.length; i++) {
            if (this.DialogArray[i][0].name == name)
                return this.DialogArray[i][0];
        }
        return null;
    }
    //是否存在名称为name的打开的窗口
    this.ExistDialogByUserID = function(userid) {
        for (var i = 0; i < this.DialogArray.length; i++) {
            if (this.DialogArray[i][2] == userid)
                return this.DialogArray[i][0];
        }
        return null;
    }
    //找到 名称为name的打开窗口的索引
    this.IndexOf = function(name) {
        for (var i = 0; i < this.DialogArray.length; i++) {
            if (this.DialogArray[i][0].name == name)
                return i;
        }
        return -1;
    }
    //移除名为name的窗口，parentWindowClosed指示移除窗口是否由父窗体触发，
    //closeChild指示是否关闭子窗体
    this.Remove = function(name, parentWindowClosed, closeChild) {
        var i = this.IndexOf(name);
        if (i >= 0) {
            if (parentWindowClosed != null && parentWindowClosed == true)
                this.DialogArray[i][0].parentClose = true;
            else
                this.DialogArray[i][0].parentClose = false;
            if (closeChild == true)
                this.DialogArray[i][0].close();
            this.DialogArray.splice(i, 1);
        }
        if (this.ExistNotChatRoom() == false)
            remaskBody(maskDivId);
    }


    //打开一个新的窗口 isChatRoom指示是否为聊天室窗口
    this.Open = function(url, name, feathures, isChatRoom, userid) {

        var winDialog = this.ExistDialog(name);
        if (winDialog == null) {
            winDialog = window.open(url, name, feathures);
            this.DialogArray.push([winDialog, isChatRoom, userid]);
        }
        else {
            window.focus();
            alert("您已经打开了该窗体！");
        }
        winDialog.focus();

        if (isChatRoom == false)
            maskBody("50", maskDivId);
    }


    this.Clear = function(parentWindowClosed) {
        for (var i = 0; i < this.DialogArray.length; i++) {
            if (parentWindowClosed != null && parentWindowClosed == true && this.DialogArray[i][0]!=null)
                this.DialogArray[i][0].parentClose = true;
            else
                this.DialogArray[i][0].parentClose = false;

            this.DialogArray[i][0].close();
        }
        if (this.DialogArray.length > 0)
            this.DialogArray.splice(0, this.DialogArray.length);
        remaskBody(maskDivId);
    }
}

// 辅助方法
function GetGuid() {
    return chatblog.usercate.chRoom.GetNewGuid().value;
}

document.body.onkeydown = function(e) {
    e = e || window.event;
    if (e.keyCode == '116') {
        e.keyCode = '0';
        clearEventBubble(e);
        return false ;
    }
} 